package com.atguigu.mq.route;

import com.atguigu.mq.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Producer {
    public static void main(String[] args) throws Exception {
        String exchange="route_change";
        String queue="route_queue1";
        String queue2="route_queue2";
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        //BuiltinExchangeType.FANOUT 广播式交换机
        //BuiltinExchangeType.DIRECT 定向路由
        channel.exchangeDeclare(exchange, BuiltinExchangeType.DIRECT,true,false,null);

        //声明队列
        channel.queueDeclare(queue,true,false,false,null);
        channel.queueDeclare(queue2,true,false,false,null);
        //绑定关系
        channel.queueBind(queue,exchange,"hello route");
        channel.queueBind(queue2,exchange,"hi spring");

        String message="hellomq_route";
        channel.basicPublish(exchange,"hello route",null,message.getBytes());

        channel.close();
        connection.close();
    }
}
